//
//  LSZFansViewController.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/8/10.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZFansViewController.h"

@interface LSZFansViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView * tableViewOne;
@property(nonatomic,assign) NSInteger page;
@property(nonatomic,strong) NSMutableArray * arrayMutData;
@property(nonatomic,strong) LSZEmptyDataVC * emptyDataVC;
@end

@implementation LSZFansViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}
-(void)getFansData:(NSInteger)page
{
    __weak typeof(self) weakSelf = self;
    [LSZRequestResolutionDic initWithAttentionFans:weakSelf.urlString fuid:weakSelf.fuid page:[NSString stringWithFormat:@"%ld",(long)page] :^(BOOL isOk, NSString * string, LSZAttentionFansManager * manager) {
        if (isOk == YES) {
            if (page == 1) {
                [weakSelf.arrayMutData removeAllObjects];
                [weakSelf.arrayMutData addObjectsFromArray:manager.arrayData];
                if (manager.arrayData.count == 0) {
                    weakSelf.tableViewOne.mj_footer.hidden = YES;
                    weakSelf.emptyDataVC = [[LSZEmptyDataVC alloc]init];
                    [weakSelf.emptyDataVC showWithView:weakSelf.tableViewOne];
                }
            }else{
                [weakSelf.arrayMutData addObjectsFromArray:manager.arrayData];
                if (manager.arrayData.count == 0) {
                    [weakSelf.tableViewOne.mj_footer endRefreshingWithNoMoreData];
                }
            }
            [weakSelf.tableViewOne reloadData];
        }else{
            [weakSelf initWithtring:string];
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.page = 1;
    self.arrayMutData = [NSMutableArray array];
    [self getFansData:self.page];
    [self.tableViewOne registerClass:[LSZFansTableViewCell class] forCellReuseIdentifier:@"LSZFansTableViewCell"];
    self.tableViewOne.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        self.page = 1;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self getFansData :self.page];
            [self.tableViewOne.mj_header endRefreshing];
        });
    }];
    self.tableViewOne.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        self.page++;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self getFansData:self.page];
            [self.tableViewOne.mj_footer endRefreshing];
        });
    }];
 }
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrayMutData.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = [LSZSpecialPackaging initWithReturnsthesizeOf:80 :5];
    return height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0001;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZFansTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZFansTableViewCell" forIndexPath:indexPath];
    __weak typeof(self) weakSelf = self;
    if (self.arrayMutData.count > indexPath.row) {
        LSZAttentionFansMg * mg = nil;
        mg = weakSelf.arrayMutData[indexPath.row];
        cell.attentionFansMg = mg;
        [cell.butFocusOn tapGesture:^(UIGestureRecognizer *ges) {
            [weakSelf clickButFocusOnDetaill:mg.uid :indexPath.row :mg];
        }];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
#pragma mark - 关注
-(void)clickButFocusOnDetaill :(NSString *)uid :(NSInteger)row :(LSZAttentionFansMg *)mg
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVC;
    }else{
        [LSZRequestData payAttentionToOthers:uid Ck:@"0" mode:@"0" :^(BOOL isOk, NSString * str, NSDictionary * dic) {
            if (isOk == YES) {
                [self initWithtring:@"关注成功!"];
                LSZFansTableViewCell * cell = (LSZFansTableViewCell *)[self.tableViewOne cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row  inSection:0]];
                [cell.butFocusOn setTitle:@"已关注" forState:UIControlStateNormal];
                cell.butFocusOn.backgroundColor = partialShallow;
                cell.butFocusOn.userInteractionEnabled = NO;
            }else{
                [self initWithtring:str];
            }
        }];
    }
}
-(UITableView *)tableViewOne
{
    if(_tableViewOne== nil){
        _tableViewOne = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-NAVIGATION_BAR_HEIGHT-50) style:UITableViewStylePlain];
        _tableViewOne.delegate = self;
        _tableViewOne.dataSource = self;
        _tableViewOne.separatorColor = divider;
        _tableViewOne.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);
        _tableViewOne.estimatedRowHeight =0;
        _tableViewOne.estimatedSectionFooterHeight =0;
        _tableViewOne.estimatedSectionHeaderHeight =0;
        [self.view addSubview:_tableViewOne];
    }
    return _tableViewOne;
}
@end
